//
//  LGTUserInfoViewCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/16.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTUserInfoViewCell: UITableViewCell {

    var titleLabel:UILabel?
    var subLabel:UILabel?
    var iconImageView:UIImageView?
    var _data:Dictionary<String, Any>?
    var data:Dictionary<String, Any>?{
        get{
            return _data
        }
        set{
            _data = newValue
            self.setInit()
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: UserCell_Set_Size)
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ (make) in
            make.centerY.equalTo(self)
            make.height.equalTo(UserCell_Set_Size)
            make.left.equalTo(SizeFit(12))
        })
        
        self.subLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.right, textColor: TextColor, fontSize: UserCell_Set_Size)
        self.addSubview(self.subLabel!)
        self.subLabel?.snp.makeConstraints({ (make) in
            make.centerY.equalTo(self)
            make.height.equalTo(UserCell_Set_Size)
            make.right.equalTo(-SizeFit(35))
        })
        
        self.iconImageView = LGTViewCreateUtil.share.createImageViewCorner(corner: CGFloat(SizeFit(18)), imageName: "")
        self.addSubview(self.iconImageView!)
        self.iconImageView?.snp.makeConstraints({ (make) in
            make.width.height.equalTo(SizeFit(36))
            make.centerY.equalTo(self)
            make.right.equalTo(-SizeFit(35))
        })
        
//        self.titleLabel?.text = "title"
//        self.subLabel?.text = "sublabel"
        //self.iconImageView?.backgroundColor = UIColor.orange
        
        let line:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(12))
            make.right.equalTo(SizeFit(-12))
            make.height.equalTo(1)
            make.bottom.equalTo(0)
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setInit(){
        self.titleLabel?.text = (self.data?["title"] ?? "") as? String
        self.subLabel?.text = ((self.data?["text"] ?? "") as! String)
        let icon:String = (self.data?["icon"] ?? "") as! String
        if icon.count > 0{
            self.iconImageView?.isHidden = false
            //self.iconImageView?.setWebImage(url: icon)
            BaseUtil.baseUtil.setImage(imageView: self.iconImageView!, imageUrl: icon, type: BaseUtil.ImageDefaultType.UserImageType)
            //self.iconImageView?.setWebImage(url: icon)
        }else{
            self.iconImageView?.isHidden = true
        }
    }
}
